package com.zj.transactionspringboot01.service.impl;

import com.zj.transactionspringboot01.domain.Teacher;
import com.zj.transactionspringboot01.service.IupdateDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Component
public class TeacherUpdateService implements IupdateDao<Teacher> {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public int updatePOJO(Teacher teacher) {
        String sql = "update teacher set name=?,phonenum=? ,address=? where  idno=?";
        int res = jdbcTemplate.update(sql, teacher.getName(), teacher.getPhonenum(), teacher.getAddress(), teacher.getIdno());
        return res;
    }
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public int updatePOJO1(Teacher teacher) {
        int res = updatePOJO(teacher);
        int i = 1 / 0;
        return res;
    }
    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public int updatePOJO2(Teacher teacher) {
        int res = updatePOJO(teacher);
        int i = 1 / 0;
        return res;
    }
    @Override
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public int updatePOJO3(Teacher teacher) {
        int res = updatePOJO(teacher);
        int i = 1 / 0;
        return res;
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public int updatePOJO4(Teacher teacher) {
        int res = updatePOJO(teacher);
        int i = 1 / 0;
        return res;
    }

    @Override
    @Transactional(propagation = Propagation.MANDATORY)
    public int updatePOJO5(Teacher teacher) {
        int res = updatePOJO(teacher);
//        int i = 1 / 0;
        return res;
    }
    @Override
    @Transactional(propagation = Propagation.NEVER)
    public int updatePOJO6(Teacher teacher) {
        int res = updatePOJO(teacher);
//        int i = 1 / 0;
        return res;
    }
    @Override
    @Transactional(propagation = Propagation.NESTED)
    public int updatePOJO7(Teacher teacher) {
        int res = updatePOJO(teacher);
//        int i = 1 / 0;
        return res;
    }
}
